package vip.meeet.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import vip.meeet.bean.Result;
import vip.meeet.bean.echarts.ChartType;
import vip.meeet.bean.echarts.EData;
import vip.meeet.bean.echarts.PieData;
import vip.meeet.helper.EchartsHelper;
import vip.meeet.helper.ResultHelper;

import java.util.LinkedList;

@Controller
@RequestMapping("/pie")
public class PieController {


    @RequestMapping("/one")
    @ResponseBody
    public Result one(){
        LinkedList<PieData> datas = new LinkedList<>();
        LinkedList<String> legend = new LinkedList<>();
        for(int i=1;i<=10;i++){
            PieData<Object> pieData = new PieData<>();
            String name = "name" + i;
            pieData.setName(name);
            pieData.setValue(i + 5);
            legend.add(name);
            datas.add(pieData);
        }
        EData data = EchartsHelper.buildSerie(ChartType.PIE, "TM", datas);
        JSONObject result = EchartsHelper.buildPieResult(
                "交通",
                legend,
                data
        );
        return ResultHelper.getSuccessResult(result);
    }


}
